<?php
namespace app\admin\controller;
use app\admin\controller\Base;
use app\admin\model\Admin;
use app\admin\model\Setting;
use think\Request;

class  Set extends Base
{

    public function varlist(){
        $user = $this->user_info();
        $data = array(
            "setting" => $this->getAllSetting(),
            "list" => Setting::order("sort asc")->select(),
        );
        return view("varlist",$data);
    }

    //添加
    public function addform(){
        $user = $this->user_info();
        $data = array(
            "setting" => $this->getAllSetting(),
        );
        return view("addform",$data);
    }
    public function add(Request $request){
        $data = $request->post();
        if(Setting::insert($data)){
            $this->success("添加变量成功","Set/varlist");
        }else{
            $this->error("添加变量失败","Set/addform");
        }

    }
    //编辑
    public function update(Request $request){
        $user = $this->user_info();
        $data = array(
            "setting" => $this->getAllSetting(),
            "data" => Setting::where(array('id'=>$request->get('id')))->find(),
        );
        return view("update",$data);
    }
    public function edit(Request $request){
        $data = $request->post();
        if(Setting::update($data)){
            $this->success("更新变量成功","Set/varlist");
        }else{
            $this->error("更新变量失败","Set/update");
        }

    }
    //删除
    public function delete(Request $request){
        $user = $this->user_info();
        if(Setting::destroy($request->post('id'))){
            $this->success("删除变量成功","Set/varlist");
        }else{
            $this->error("删除变量失败","Set/varlist");
        }
    }




}
